package com.yyq.sos.util;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.yyq.adms.sysmanage.dao.impl.SysParametersDaoImpl;
import com.yyq.servlets.ApplicationContextHandle;

public class SessionFactoryUtil {

	private static SessionFactoryUtil sfu;
	@Autowired
	private SessionFactory sessionFactory;
	
	public static SessionFactoryUtil getInstance(){
		if(sfu==null){
			sfu = new SessionFactoryUtil();
		}
		return sfu;
	}
	
	public Session getSession(){
		if(sessionFactory==null){
			sessionFactory = (SessionFactory)ApplicationContextHandle.getBean("sessionFactory");
		}
		return sessionFactory.openSession();
	}
	
}
